package com.web.forms;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.web.util.string.StringUtil;

public class UserForm extends ActionForm {

	private String id;
	private String emailAddress;
	private String password;
	private String password1;
	private String firstName;
	private String lastName;
	private String country;
	private int sex;
	private int age;
	private Date dateCreated;
	private Date dateUpdated;
	
	@Override
	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
		// TODO Auto-generated method stub
		ActionErrors errors = new ActionErrors();
		
		if (StringUtil.isNullOrEmpty(emailAddress)) {
			errors.add("emailAddress", new ActionMessage("errors.signup.required", "E-mail address"));
		}
		
		if (StringUtil.isNullOrEmpty(password)) {
			errors.add("password", new ActionMessage("errors.signup.required", "Password"));
		}
		
		if (!password.equals(password1)) {
			errors.add("password1", new ActionMessage("errors.signup.password"));
		}
		
		if (StringUtil.isNullOrEmpty(firstName)) {
			errors.add("firstName", new ActionMessage("errors.signup.required", "First name"));
		}
		
		if (StringUtil.isNullOrEmpty(lastName)) {
			errors.add("lastName", new ActionMessage("errors.signup.required", "Last name"));
		}
		
		if (StringUtil.isNullOrEmpty(country)) {
			errors.add("country", new ActionMessage("errors.signup.required", "Country"));
		}
		
		if (sex==0) {
			errors.add("sex", new ActionMessage("errors.signup.required", "Sex"));
		}
		
		if (age==0) {
			errors.add("age", new ActionMessage("errors.signup.required", "Age"));
		}
		
		return errors;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public Date getDateCreated() {
		return dateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		this.dateCreated = dateCreated;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword1() {
		return password1;
	}

	public void setPassword1(String password1) {
		this.password1 = password1;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}
	
	
}
